package com.polaris.live.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import com.polaris.live.R
import com.polaris.live.common.ext.toLevel
import com.polaris.live.databinding.WidgetAnchorLevelBinding

/**
 * AnchorLevelView 主播等级View
 * @author Created by 天晴 on 2024/1/24 19:17
 * @since 1.0.0
 **/
class AnchorLevelView(context: Context, attributeSet: AttributeSet) :
    RelativeLayout(context, attributeSet) {

    private val mBinding = WidgetAnchorLevelBinding.inflate(LayoutInflater.from(context), this)

    /**
     * 设置等级
     */
    fun setLevel(level: Long) {
        var imgRes = 0
        imgRes = when (level.toLevel) {
            0 -> R.drawable.ic_anchor_0
            1 -> R.drawable.ic_anchor_1
            2 -> R.drawable.ic_anchor_2
            3 -> R.drawable.ic_anchor_3
            4 -> R.drawable.ic_anchor_4
            5 -> R.drawable.ic_anchor_5
            6 -> R.drawable.ic_anchor_6
            else -> R.drawable.ic_anchor_0
        }
        mBinding.bg.setImageResource(imgRes)
    }
}